<template>
  <el-menu
    active-text-color="#409eff"
    :unique-opened="true"
    :collapse-transition="false"
    router
    :default-active="activePath"
  >
    <div v-for="(items, index) in menulist" :key="index" :index="index + ''">
      <el-menu-item
        v-if="!items.children"
        :index="items.path + ''"
        @click="saveAsideState(items.path)"
      >
        <i :class="items.icon"></i>
        <span>{{ items.authName }}</span>
      </el-menu-item>

      <el-submenu v-else :key="index" :index="index + ''">
        <template slot="title">
          <i :class="items.icon"></i>
          <span>{{ items.authName }}</span>
        </template>
        <el-menu-item
          v-for="subitems in items.children"
          :key="subitems.id"
          :index="subitems.path + ''"
          @click="saveAsideState(subitems.path)"
        >
          <i class="el-icon-menu"></i>
          <span>{{ subitems.authName }}</span>
        </el-menu-item>
      </el-submenu>
    </div>
  </el-menu>
</template>

<script>
import bus from "../evenBus.js";

export default {
  data() {
    return {
      menulist: [
        {
          authName: "首页",
          path: "/welcome",
          icon: "el-icon-data-line",
        },
        // {
        //   authName: "留言管理",
        //   path: "/consultation",
        //   icon: "el-icon-collection",
        // },
        {
          authName: "用户管理",
          path: "/users",
          icon: "el-icon-user",
          // children: [
            // { authName: "用户列表", path: "/users" },
            // { authName: '用户详情', path: '/add', },
          // ],
        },
        {
          authName: "内容管理",
          path: "/content",
          icon: "el-icon-document-copy",
        },
        {
          authName: "菜品管理",
          path: "/menu",
          icon: "el-icon-orange",
        },
      ],
      // 存储链接地址
      activePath: "",
    };
  },
  methods: {
    // 通过evenbug传递数据到Home
    emitdata() {
      bus.$emit("share", this.welcome);
    },
    // 保持链接的激活
    saveAsideState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
    },
  },
  created() {
    // 通过evenbug传递数据到Home
    this.emitdata();

    // 获取存储链接地址
    this.activePath = window.sessionStorage.getItem("activePath");

    // 对某个键的值是否为空进行判断
    if (!window.sessionStorage.getItem("activePath")) {
      this.activePath = "welcome";
      // console.log('已经获取')
    }
    // console.log(this.menulist);
  },
};
</script>

<style lang="less" scoped>
// 去掉aside边框线，两种方法都可
// .tac {
//     overflow: hidden;

//     .el-col {
//         width: 101%;

//     }
// }
.el-menu {
  border: none;
}

.iconfont {
  margin-right: 10px;
}

.el-icon-magic-stick {
  width: auto !important;

  // margin-right: 10px;
}
</style>
